package Hangman;

import javax.swing.JComponent;
/**
 * Word class, used to handle each Word, by having an array of Letter objects.
 * @author Robin E, Jakob L, Isac A, Cristian O, Eric P, Tobias W. 
 *
 */
@SuppressWarnings("serial")
public class Word extends JComponent{
	private FileLoader fl= new FileLoader();
	private Letter[] word;
	
	/**
	 * Word() simple constructor which generates the list and retrieves an random word.
	 */
	public Word()
	{
		fl.generateList();
		word=fl.getRandomWord().getWord();
	}
	
	/**
	 * Word(Letter[] word) creates an Word object and set it as a specific array of Letters already made.
	 * @param word the letter array to be used.
	 */
	public Word(Letter[] word) {
		super();
		this.word = word;
	}
	
	/**
	 * getWord() is used to retrieve the word (Array of Letters)
	 * @return word the letter array
	 */
	public Letter[] getWord() {
		return word;
	}
	/**
	 * setWord(Letter[] word) is used to set the array of letter to a new array of letters
	 * @param word the array to be changed to
	 */
	public void setWord(Letter[] word) {
		this.word = word;
	}
	/**
	 * toString()
	 * Prints the word by iterating through the array and calling each letter toString() method
	 * which in turn will show the word with hidden '_' and visible letters.
	 */
	public String toString()
	{
		String tmp = "";
		
		for(int i = 0; i < word.length; i++)
		{
			tmp += word[i].toString() + " ";
		}
		
		return tmp;
	}
		
}
